var popUpBase={
	$:function(id){return document.getElementById(id)}
	,tagArr:function(o,name){return o.getElementsByTagName(name)}
	,att:function(o,name,fun){return document.all ? o.attachEvent(name,fun) : o.addEventListener(name.substr(2),fun,false);}
	,style:function(o){	//获取全局样式表、内嵌样式（不能设置）
		return o.currentStyle || document.defaultView.getComputedStyle(o,null);
	}
	,buildElement:function(tagName,parentObj){
		var obj=document.createElement(tagName);
		parentObj.appendChild(obj);
		return obj;
	}
	,dElement:function(){//兼容DTD头
		return	document.documentElement || document.body;
	}
	,rewriteAtt:function(formerObj,newObj){//给对象设置属性
		for(var i in newObj){
			formerObj[i]=newObj[i];
		}
		return formerObj;
	}
	,getUrlParameter:function(url){//获取路径参数
		url=url.split('?')[1];
		if(!url){return null;}
		var arr=url.split('&'),len=arr.length,i,object={};
		for(i=0;i<len;i++){
			var text=arr[i].split('=');
			object[text[0]]=text[1];
		}
		return object;
	}
};

/*显示层类*/
var popUpLayer=function(newObj){
	this.base=popUpBase;
	var pro=this;
	pro=this.base.rewriteAtt(pro,newObj);
	this.show();
};
popUpLayer.prototype={
	show:function(){
		this.obj=this.base.buildElement('div',document.body);
		this.obj.id=this.id;
		this.obj.className=this.conObj.css;
		this.sizePlace();
		if(this.eventCallBack)this.eventCallBack();
		this.obj.innerHTML=this.html();
		this.addAtt();
		if(this.showCallBack)this.showCallBack();
	}
	,html:function(){
		var text=this.templet;
		text=text.replace('{@inTow@}',(this.inTowClass?'onmousedown="this[\'pro\'].inTowClass.down();"':''));
		text=text.replace('{@title@}',this.conObj.title);
		text=text.replace('{@close@}','onclick="this[\'pro\'].close();"');
		text=text.replace('{@con@}',this.conObj.con);
		return text;
	}
	,addAtt:function(){
		var arr=this.base.tagArr(this.obj,'*'),len=arr.length,i;
		for(i=0;i<len;i++){
			arr[i]['pro']=this;
		}
	}
	,sizePlace:function(){
		var dEl=this.base.dElement();
		var l=(dEl.clientWidth-this.conObj.width)/2;
		var t=dEl.scrollTop+((dEl.clientHeight-this.conObj.height)/2);
		with(this.obj.style){
			zIndex=this.conObj.zIndex+1;
			left=l+'px';
			top=(t>0?t:0)+'px';
			width=this.conObj.width+'px';
			height=this.conObj.height+'px';
		}
	}
	,close:function(){
		if(this.closeCallBack)this.closeCallBack();
	}
};
/*背景层类*/
var popUpbg=function(newObj){
	this.base=popUpBase;
	var pro=this;
	pro=this.base.rewriteAtt(pro,newObj);
	this.show();
};
popUpbg.prototype={
	show:function(){
		this.obj=this.base.buildElement('div',document.body);
		this.obj.id=this.id;
		this.obj.className=this.css;
		this.sizePlace();
	}
	,sizePlace:function(){
		var dEl=this.base.dElement();
		var w=dEl.scrollWidth>dEl.clientWidth?dEl.scrollWidth:dEl.clientWidth;
		var h=dEl.scrollHeight>dEl.clientHeight?dEl.scrollHeight:dEl.clientHeight;
		with(this.obj.style){
			zIndex=this.zIndex;
			width=w+'px';
			height=h+'px';
		}
		this.obj.innerHTML='<iframe style="width:100%;height:'+h+'px;filter:alpha(opacity=0);opacity:0"></iframe>';
	}
};
/*关闭层*/
var popUpClose=function(arr){
	var len=arr.length,i,base=popUpBase;
	for(i=0;i<len;i++){
		var obj=base.$(arr[i]);
		obj.parentNode.removeChild(obj);
	}
};
/*适配层*/
function popUpAdapter(id,conObj,callBack,collocate){
	var base=popUpBase;
	var dEl=base.dElement();
	var w=dEl.scrollWidth>dEl.clientWidth?dEl.scrollWidth:dEl.clientWidth;
	var h=dEl.scrollHeight>dEl.clientHeight?dEl.scrollHeight:dEl.clientHeight;
	new popUpLayer({
		templet:popUpTemplet(conObj.conHeight)
		,id:id,conObj:conObj
		,closeCallBack:function(){
			popUpClose([id,id+'_bg']);
			if(callBack){callBack(this.obj);}
		}
	});
	new popUpbg({
		id:id+'_bg'
		,css:conObj.bgCss
		,zIndex:conObj.zIndex
	});
}
/*模板层*/
var popUpTemplet=function(height){
	var str='';
	str+='<div class="popUpHead">';
	str+='	<label {@inTow@}>{@title@}</label><span {@close@}></span>';
	str+='</div>';
	str+='<div class="popUpBody" style="height:'+height+'px;">{@con@}</div>';
	return str;
};
